<template>
    <div class="achieveBasicInfo container">
        <div id="components-form-demo-advanced-search">
            <div class="tabCommonTitle">
                <span>申报表</span>
            </div>
            <!-- 成果简介 -->
            <div class="declareTableInfo">
                <div class="title">
                    <span>成果简介<em>（请上传doc格式，1000字以内）</em></span>
                    <div class="flex_box">
                        <div style="width: 200px;">
                            <a-progress :percent="xmjj_percent" v-show="xmjj_percent_flag"/>
                        </div>
                        <div class="btnList">
                            <a-button class="loadboard" @click="loadboard_xmjj">模板下载</a-button>
                            <a-button @click="handlePreview_xmjj" :disabled="xmjjlist&&xmjjlist.id?false:true">预览</a-button>
                            <!-- <a-button @click="handleDownload_xmjj" :disabled="xmjjlist&&xmjjlist.id?false:true">下载</a-button> -->
                            <a-button :class="is_modify=='Y'?'download':''" @click="handleUpload_xmjj" type="primary" :disabled="is_modify=='Y'?false:true">上传</a-button>
                            <!-- accept=".doc,.docx,application/msword" -->
                            <input type="file" class="pointer xmjj" id="xmjj" accept=".doc" @change="handleUploadxmjj"/>
                        </div>
                    </div>
                </div>
                <div class="tableList">
                    <table style="text-align:center;" width="1110"  align="center" cellpadding="">
                        <thead>
                            <tr>
                                <th>是否上传成功</th>
                                <th>文件大小（M）</th>
                                <th>文件类型</th>
                                <th>当前字数</th>
                            </tr>
                        </thead>
                        <tbody v-if="xmjjlist&&xmjjlist.id">
                            <tr>
                                <td>{{xmjjlist.filePdfpath!='' ?'成功':''}}</td>
                                <td>{{xmjjlist.fileSize}}</td>
                                <td>{{xmjjlist.fileType}}</td>
                                <td>{{xmjjlist.fileNumber}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <!-- 主要创新点与内涵 -->
            <div class="declareTableInfo">
                <div class="title">
                    <span>主要创新点与内涵<em>（请上传doc格式，	5000字以内）</em></span>
                    <div class="flex_box">
                        <div style="width: 200px;">
                            <a-progress :percent="cxd_percent" v-show="cxd_percent_flag"/>
                        </div>
                        <div class="btnList">
                            <a-button class="loadboard" @click="loadboard_cxd">模板下载</a-button>
                            <a-button @click="handlePreview_cxd" :disabled="cxdlist&&cxdlist.id?false:true">预览</a-button>
                            <!-- <a-button @click="handleDownload_cxd" :disabled="cxdlist&&cxdlist.id?false:true">下载</a-button> -->
                            <a-button :class="is_modify=='Y'?'download':''" type="primary" @click="handleUpload_cxd" :disabled="is_modify=='Y'?false:true">上传</a-button>
                            <input type="file" class="pointer cxd" id="cxd" accept=".doc" @change="handleUploadcxd"/>
                        </div>
                    </div>
                </div>
                <div class="tableList">
                    <table style="text-align:center;" width="1110"  align="center" cellpadding="">
                        <thead>
                            <tr>
                                <th>是否上传成功</th>
                                <th>文件大小（M）</th>
                                <th>文件类型</th>
                                <th>当前字数</th>
                            </tr>
                        </thead>
                        <tbody v-if="cxdlist&&cxdlist.id">
                            <tr>
                                <td>{{cxdlist.filePdfpath!='' ?'成功':''}}</td>
                                <td>{{cxdlist.fileSize}}</td>
                                <td>{{cxdlist.fileType}}</td>
                                <td>{{cxdlist.fileNumber}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <!-- 实施应用情况 -->
            <div class="declareTableInfo">
                <div class="title">
                    <span>实施应用情况<em>（请上传doc格式，800字以内）</em></span>
                    <div class="flex_box">
                        <div style="width: 200px;">
                            <a-progress :percent="ssyy_percent" v-show="ssyy_percent_flag"/>
                        </div>
                        <div class="btnList">
                            <a-button class="loadboard" @click="loadboard_ssyy">模板下载</a-button>
                            <a-button @click="handlePreview_ssyy" :disabled="ssyylist&&ssyylist.id?false:true">预览</a-button>
                            <!-- <a-button @click="handleDownload_ssyy" :disabled="ssyylist&&ssyylist.id?false:true">下载</a-button> -->
                            <a-button :class="is_modify=='Y'?'download':''" type="primary" @click="handleUpload_ssyy" :disabled="is_modify=='Y'?false:true">上传</a-button>
                            <input type="file" class="pointer ssyy" id="ssyy" accept=".doc" @change="handleUploadssyy"/>
                        </div>
                    </div>
                </div>
                <div class="tableList">
                    <table style="text-align:center;" width="1110"  align="center" cellpadding="">
                        <thead>
                            <tr>
                                <th>是否上传成功</th>
                                <th>文件大小（M）</th>
                                <th>文件类型</th>
                                <th>当前字数</th>
                            </tr>
                        </thead>
                        <tbody v-if="ssyylist&&ssyylist.id">
                            <tr>
                                <td>{{ssyylist.filePdfpath!='' ?'成功':''}}</td>
                                <td>{{ssyylist.fileSize}}</td>
                                <td>{{ssyylist.fileType}}</td>
                                <td>{{ssyylist.fileNumber}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <!-- 社会效益与间接经济效益 -->
            <div class="declareTableInfo">
                <div class="title">
                    <span>社会效益与间接经济效益<em>（请上传doc格式，500字以内）</em></span>
                    <div class="flex_box">
                        <div style="width: 200px;">
                            <a-progress :percent="shxy_percent" v-show="shxy_percent_flag"/>
                        </div>
                        <div class="btnList">
                            <a-button class="loadboard" @click="loadboard_shxy">模板下载</a-button>
                            <a-button @click="handlePreview_shxy" :disabled="shxylist&&shxylist.id?false:true">预览</a-button>
                            <!-- <a-button @click="handleDownload_shxy" :disabled="shxylist&&shxylist.id?false:true">下载</a-button> -->
                            <a-button :class="is_modify=='Y'?'download':''" type="primary" @click="handleUpload_shxy" :disabled="is_modify=='Y'?false:true">上传</a-button>
                            <input type="file" class="pointer shxy" id="shxy" accept=".doc" @change="handleUploadshxy"/>
                        </div>
                    </div>
                </div>
                <div class="tableList">
                    <table style="text-align:center;" width="1110"  align="center" cellpadding="">
                        <thead>
                            <tr>
                                <th>是否上传成功</th>
                                <th>文件大小（M）</th>
                                <th>文件类型</th>
                                <th>当前字数</th>
                            </tr>
                        </thead>
                        <tbody v-if="shxylist&&shxylist.id">
                            <tr>
                                <td>{{shxylist.filePdfpath!='' ?'成功':''}}</td>
                                <td>{{shxylist.fileSize}}</td>
                                <td>{{shxylist.fileType}}</td>
                                <td>{{shxylist.fileNumber}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <!-- 研究报告 -->
            <div class="declareTableInfo">
                <div class="title">
                    <span>研究报告<em>（请上传doc格式，2万字以内）</em></span>
                   <div class="flex_box">
                        <div style="width: 200px;">
                            <a-progress :percent="yjbg_percent" v-show="yjbg_percent_flag"/>
                        </div>
                        <div class="btnList">
                            <a-button class="loadboard" @click="loadboard_yjbg">模板下载</a-button>
                            <a-button @click="handlePreview_yjbg" :disabled="yjbglist&&yjbglist.id?false:true">预览</a-button>
                            <!-- <a-button @click="handleDownload_yjbg" :disabled="yjbglist&&yjbglist.id?false:true">下载</a-button> -->
                            <a-button :class="is_modify=='Y'?'download':''" type="primary" @click="handleUpload_yjbg" :disabled="is_modify=='Y'?false:true">上传</a-button>
                            <input type="file" class="pointer yjbg" id="yjbg" accept=".doc" @change="handleUploadyjbg"/>
                        </div>
                    </div>
                </div>
                <div class="tableList">
                    <table style="text-align:center;" width="1110"  align="center" cellpadding="">
                        <thead>
                            <tr>
                                <th>是否上传成功</th>
                                <th>文件大小（M）</th>
                                <th>文件类型</th>
                                <th>当前字数</th>
                            </tr>
                        </thead>
                        <tbody v-if="yjbglist&&yjbglist.id">
                            <tr>
                                <td>{{yjbglist.filePdfpath!='' ?'成功':''}}</td>
                                <td>{{yjbglist.fileSize}}</td>
                                <td>{{yjbglist.fileType}}</td>
                                <td>{{yjbglist.fileNumber}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!-- <div class="showpdf" v-if="showpdf">
            <img class="closebtn pointer" @click="closepdf" src="@/assets/img/close1.png"/>
            <testPdf :cxj_cxj_id="cxj_cxj_id" :file-path="filePath"></testPdf>
        </div> -->
        <testPdf :cxj_cxj_id="cxj_cxj_id" :file-path="filePath" :showPdf="showpdf"></testPdf>
    </div>
</template>
<script>
import {
    cxjsb_getSbbxmjj,
    cxjsb_xmjjAdd,
    cxjsb_downloadXmjjmb,
    cxjsb_getSbbcxd,
    cxjsb_cxdAdd,
    cxjsb_downloadCxdmb,
    cxjsb_getSbbssyy,
    cxjsb_ssyyAdd,
    cxjsb_downloadSbbssyymb,
    cxjsb_getSbbshxy,
    cxjsb_shxyAdd,
    cxjsb_downloadShxymb,
    cxjsb_getSbbyjbg,
    cxjsb_yjbgAdd,
    cxjsb_downloadYjbgmb,
    cxjsb_downloadYjbgmbZg,
    fileDownload
} from '@/api/shenbao';
import testPdf from '@/views/declarationSystem/declare/testPdf';
import { mapActions } from 'vuex'
export default {
    name: 'DeclareTable',
    data() {
        return {
            cxj_cxj_id: '',
            xmjjlist: {},
            cxdlist: {},
            ssyylist: {},
            shxylist: {},
            yjbglist: {},
            xmjj_percent: 0,
            xmjj_percent_flag: false,
            cxd_percent: 0,
            cxd_percent_flag: false,
            ssyy_percent: 0,
            ssyy_percent_flag: false,
            shxy_percent: 0,
            shxy_percent_flag: false,
            yjbg_percent: 0,
            yjbg_percent_flag: false,
            showpdf: false,
            filePath: '',
        }
    },
    props: ['is_modify'],
    components: {
        testPdf
    },
    methods: {
        ...mapActions('fillingSteps', ['getStatus']),
        handlePreview(){},
        handleDownload(){},
        init() {
            this.get_cxjsb_getSbbxmjj();
            this.get_cxjsb_getSbbcxd();
            this.get_cxjsb_getSbbssyy();
            this.get_cxjsb_getSbbshxy();
            this.get_cxjsb_getSbbyjbg();
        },
        get_cxjsb_getSbbxmjj() {
            let that = this;
            cxjsb_getSbbxmjj(that.cxj_cxj_id).then(res=>{
                if (res.data.code=='200') {
                    that.xmjjlist = res.data.result;
                }
            })
        },
        loadboard_xmjj() {
            let that = this;
            cxjsb_downloadXmjjmb({cxj_cxj_id:that.cxj_cxj_id}).then(res=>{
                that.downfn('项目简介',res);
            })
        },
        // closepdf() {
        //     this.filePath = '';
        //     this.showpdf = false;
        // },
        handlePreview_xmjj() {
            let that = this;
            if (this.xmjjlist && this.xmjjlist.id) {
                console.log(this.xmjjlist.filePdfpath, 'that.xmjjlist.filePdfpath=====');
                this.showpdf = !this.showpdf;
                this.filePath = that.xmjjlist.filePdfpath;
                // let routeData = this.$router.resolve({
                //     path: '/shenbao/pdfFile',
                //     query: {
                //         cxj_cxj_id: that.cxj_cxj_id,
                //         path: that.xmjjlist.filePdfpath
                //     }
                // });
                // window.open(routeData.href, '_blank');
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleDownload_xmjj() {
            let that = this;
            if (this.xmjjlist && this.xmjjlist.id) {
                fileDownload({
                    cxj_cxj_id: that.cxj_cxj_id,
                    path: that.xmjjlist.fileDocpath
                }).then(res=>{
                    that.downfn('项目简介', res)
                })
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleUpload_xmjj() {
            const choosefile = document.querySelector('#xmjj');
            choosefile.click();
        },
        handleUploadxmjj() {
            let that = this;
            that.xmjj_percent = 0;
            that.xmjj_percent_flag = true;
            const files = document.getElementById('xmjj').files[0];
            console.log('24234234324',files)
            if (files) {
                if (files.size > 50*1024*1024) { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                    this.$message.warning('文件最大为50兆')
                    return
                }
              if (files.name.substring(files.name.lastIndexOf('.')+1).toLowerCase()!='doc') { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                this.$message.warning('请上传doc格式的文件')
                return
              }
              if(window.FileReader) {
                    var fr = new FileReader();
                    fr.onprogress = function(e) {
                        that.xmjj_percent = (e.loaded/files.size)*100;
                    };
                    fr.readAsDataURL(files);
                }
                let formData = new FormData();
                formData.append('cxj_cxj_id', this.cxj_cxj_id)
                formData.append('file', files);
                if (this.xmjjlist && this.xmjjlist.id) {
                    formData.append('id', this.xmjjlist.id);
                } else {
                    formData.append('id', '');
                }

                cxjsb_xmjjAdd(formData).then(res=>{
                    console.log(res, 'res')
                    let data = res.data;
                    that.xmjj_percent_flag = false;
                    if (data.success) {
                        that.getStatus(that.cxj_cxj_id)
                        document.getElementById('xmjj').value = null;
                        that.$message.success('上传成功');
                        that.get_cxjsb_getSbbxmjj();
                    } else {
                        that.$message.error(data.message);
                    }
                }).catch(err=>{
                    console.log(err)
                    that.xmjj_percent_flag = false;
                })
            }
        },
        get_cxjsb_getSbbcxd() {
            let that = this;
            cxjsb_getSbbcxd(that.cxj_cxj_id).then(res=>{
                if (res.data.code=='200') {
                    that.cxdlist = res.data.result;
                }
            })
        },
        loadboard_cxd() {
            let that = this;
            cxjsb_downloadCxdmb({cxj_cxj_id:that.cxj_cxj_id}).then(res=>{
                that.downfn('创新点', res)
            })
        },
        handlePreview_cxd() {
            let that = this;
            if (this.cxdlist && this.cxdlist.id) {
                // this.showpdf = true;
                this.showpdf = !this.showpdf;
                this.filePath = that.cxdlist.filePdfpath;
                // let routeData = this.$router.resolve({
                //     path: '/shenbao/pdfFile',
                //     query: {
                //         cxj_cxj_id: that.cxj_cxj_id,
                //         path: that.cxdlist.filePdfpath
                //     }
                // });
                // window.open(routeData.href, '_blank');
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleDownload_cxd() {
            let that = this;
            if (this.cxdlist && this.cxdlist.id) {
                fileDownload({
                    cxj_cxj_id: that.cxj_cxj_id,
                    path: that.cxdlist.fileDocpath
                }).then(res=>{
                    that.downfn('创新点', res)
                })
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleUpload_cxd() {
            const choosefile = document.querySelector('#cxd');
            choosefile.click();
        },
        handleUploadcxd () {
            let that = this;
            that.cxd_percent = 0;
            that.cxd_percent_flag = true;
            const files = document.getElementById('cxd').files[0];
            if (files) {
                if (files.size > 50*1024*1024) { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                    this.$message.warning('文件最大为50兆')
                    return
                }
              if (files.name.substring(files.name.lastIndexOf('.')+1).toLowerCase()!='doc') { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                this.$message.warning('请上传doc格式的文件')
                return
              }
                if(window.FileReader) {
                    var fr = new FileReader();
                    fr.onprogress = function(e) {
                        that.cxd_percent = (e.loaded/files.size)*100;
                    };
                    fr.readAsDataURL(files);
                }
                let formData = new FormData();
                formData.append('cxj_cxj_id', this.cxj_cxj_id)
                formData.append('file', files);
                if (this.cxdlist && this.cxdlist.id) {
                    formData.append('id', this.cxdlist.id);
                } else {
                    formData.append('id', '');
                }
                cxjsb_cxdAdd(formData).then(res=>{
                    that.$message.success('上传中');
                    let data = res.data;
                    that.cxd_percent_flag = false;
                    if (data.success) {
                        that.getStatus(that.cxj_cxj_id)
                        document.getElementById('cxd').value = null;
                        that.$message.destroy();
                        that.$message.success('上传成功');
                        that.get_cxjsb_getSbbcxd();
                    } else {
                        that.$message.error(data.message);
                    }
                }).catch(err=>{
                    console.log(err)
                    that.cxd_percent_flag = false;
                })
            }
        },
        get_cxjsb_getSbbssyy() {
            let that = this;
            cxjsb_getSbbssyy(that.cxj_cxj_id).then(res=>{
                if (res.data.code=='200') {
                    that.ssyylist = res.data.result;
                }
            })
        },
        loadboard_ssyy() {
            let that = this;
            cxjsb_downloadSbbssyymb({cxj_cxj_id:that.cxj_cxj_id}).then(res=>{
                that.downfn('实施应用情况',res);
            })
        },
        handlePreview_ssyy() {
            let that = this;
            if (this.ssyylist && this.ssyylist.id) {
                // this.showpdf = true;
                this.showpdf = !this.showpdf;
                this.filePath = that.ssyylist.filePdfpath;
                // let routeData = this.$router.resolve({
                //     path: '/shenbao/pdfFile',
                //     query: {
                //         cxj_cxj_id: that.cxj_cxj_id,
                //         path: that.ssyylist.filePdfpath
                //     }
                // });
                // window.open(routeData.href, '_blank');
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleDownload_ssyy() {
            let that = this;
            if (this.ssyylist && this.ssyylist.id) {
                fileDownload({
                    cxj_cxj_id: that.cxj_cxj_id,
                    path: that.ssyylist.fileDocpath
                }).then(res=>{
                    that.downfn('实施应用情况', res)
                })
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleUpload_ssyy() {
            const choosefile = document.querySelector('#ssyy');
            choosefile.click();
        },
        handleUploadssyy () {
            let that = this;
            that.ssyy_percent = 0;
            that.ssyy_percent_flag = true;
            const files = document.getElementById('ssyy').files[0];
            if (files) {
                if (files.size > 50*1024*1024) { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                    this.$message.warning('文件最大为50兆')
                    return
                }
              if (files.name.substring(files.name.lastIndexOf('.')+1).toLowerCase()!='doc') { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                this.$message.warning('请上传doc格式的文件')
                return
              }
                if(window.FileReader) {
                    var fr = new FileReader();
                    fr.onprogress = function(e) {
                        that.ssyy_percent = (e.loaded/files.size)*100;
                    };
                    fr.readAsDataURL(files);
                }
                let formData = new FormData();
                formData.append('cxj_cxj_id', this.cxj_cxj_id)
                formData.append('file', files);
                if (this.ssyylist && this.ssyylist.id) {
                    formData.append('id', this.ssyylist.id);
                } else {
                    formData.append('id', '');
                }
                cxjsb_ssyyAdd(formData).then(res=>{
                    that.$message.success('上传中');
                    let data = res.data;
                    that.ssyy_percent_flag = false;
                    if (data.success) {
                        that.getStatus(that.cxj_cxj_id)
                        document.getElementById('ssyy').value = null;
                        that.$message.success('上传成功');
                        that.get_cxjsb_getSbbssyy();
                    } else {
                        that.$message.error(data.message);
                    }
                }).catch(err=>{
                    console.log(err)
                    that.ssyy_percent_flag = false;
                })
            }
        },
        get_cxjsb_getSbbshxy() {
            let that = this;
            cxjsb_getSbbshxy(that.cxj_cxj_id).then(res=>{
                if (res.data.code=='200') {
                    that.shxylist = res.data.result;
                }
            })
        },
        loadboard_shxy() {
            let that = this;
            cxjsb_downloadShxymb({cxj_cxj_id:that.cxj_cxj_id}).then(res=>{
                that.downfn('社会效益与间接经济效益',res);
            })
        },
        handlePreview_shxy() {
            let that = this;
            if (this.shxylist && this.shxylist.id) {
                // this.showpdf = true;
                this.showpdf = !this.showpdf;
                this.filePath = that.shxylist.filePdfpath;
                // let routeData = this.$router.resolve({
                //     path: '/shenbao/pdfFile',
                //     query: {
                //         cxj_cxj_id: that.cxj_cxj_id,
                //         path: that.shxylist.filePdfpath
                //     }
                // });
                // window.open(routeData.href, '_blank');
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleDownload_shxy() {
            let that = this;
            if (this.shxylist && this.shxylist.id) {
                fileDownload({
                    cxj_cxj_id: that.cxj_cxj_id,
                    path: that.shxylist.fileDocpath
                }).then(res=>{
                    that.downfn('社会效益与间接经济效益', res)
                })
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleUpload_shxy() {
            const choosefile = document.querySelector('#shxy');
            choosefile.click();
        },
        handleUploadshxy() {
            let that = this;
            that.shxy_percent = 0;
            that.shxy_percent_flag = true;
            const files = document.getElementById('shxy').files[0];
            if (files) {
                if (files.size > 50*1024*1024) { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                    this.$message.warning('文件最大为50兆')
                    return
                }
              if (files.name.substring(files.name.lastIndexOf('.')+1).toLowerCase()!='doc') { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                this.$message.warning('请上传doc格式的文件')
                return
              }
                if(window.FileReader) {
                    var fr = new FileReader();
                    fr.onprogress = function(e) {
                        that.shxy_percent = (e.loaded/files.size)*100;
                    };
                    fr.readAsDataURL(files);
                }
                let formData = new FormData();
                formData.append('cxj_cxj_id', this.cxj_cxj_id)
                formData.append('file', files);
                if (this.shxylist && this.shxylist.id) {
                    formData.append('id', this.shxylist.id);
                } else {
                    formData.append('id', '');
                }
                cxjsb_shxyAdd(formData).then(res=>{
                    let data = res.data;
                    that.shxy_percent_flag = false;
                    if (data.success) {
                        that.getStatus(that.cxj_cxj_id)
                        document.getElementById('shxy').value = null;
                        that.$message.success('上传成功');
                        that.get_cxjsb_getSbbshxy();
                    } else {
                        that.$message.error(data.message);
                    }
                }).catch(err=>{
                    console.log(err)
                    that.shxy_percent_flag = false;
                })
            }
        },
        get_cxjsb_getSbbyjbg() {
            let that = this;
            cxjsb_getSbbyjbg(that.cxj_cxj_id).then(res=>{
                if (res.data.code=='200') {
                    that.yjbglist = res.data.result;
                }
            })
        },
        loadboard_yjbg() {
            let that = this;
            let data = { cxj_cxj_id: that.cxj_cxj_id }
            if (this.$route.query.type === '61') {
                cxjsb_downloadYjbgmbZg(data).then(res=>{
                    that.downfn('研究报告', res)
                })
            } else {
                cxjsb_downloadYjbgmb(data).then(res=>{
                    that.downfn('研究报告',res);
                })
            }
        },
        handlePreview_yjbg() {
            let that = this;
            if (this.yjbglist && this.yjbglist.id) {
                // this.showpdf = true;
                this.showpdf = !this.showpdf;
                this.filePath = that.yjbglist.filePdfpath;
                // let routeData = this.$router.resolve({
                //     path: '/shenbao/pdfFile',
                //     query: {
                //         cxj_cxj_id: that.cxj_cxj_id,
                //         path: that.yjbglist.filePdfpath
                //     }
                // });
                // window.open(routeData.href, '_blank');
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleDownload_yjbg() {
            let that = this;
            if (this.yjbglist && this.yjbglist.id) {
                fileDownload({
                    cxj_cxj_id: that.cxj_cxj_id,
                    path: that.yjbglist.fileDocpath
                }).then(res=>{
                    that.downfn('研究报告', res)
                })
            } else {
                this.$message.error('请上传文件');
            }
        },
        handleUpload_yjbg() {
            const choosefile = document.querySelector('#yjbg');
            choosefile.click();
        },
        handleUploadyjbg() {
            let that = this;
            that.yjbg_percent = 0;
            that.yjbg_percent_flag = true;
            const files = document.getElementById('yjbg').files[0];
            if (files) {
                if (files.size > 50*1024*1024) { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                    this.$message.warning('文件最大为50兆')
                    return
                }
              if (files.name.substring(files.name.lastIndexOf('.')+1).toLowerCase()!='doc') { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
                this.$message.warning('请上传doc格式的文件')
                return
              }
                if(window.FileReader) {
                    var fr = new FileReader();
                    fr.onprogress = function(e) {
                        that.yjbg_percent = (e.loaded/files.size)*100;
                    };
                    fr.readAsDataURL(files);
                }
                let formData = new FormData();
                formData.append('cxj_cxj_id', this.cxj_cxj_id)
                formData.append('file', files);
                if (this.yjbglist && this.yjbglist.id) {
                    formData.append('id', this.yjbglist.id);
                } else {
                    formData.append('id', '');
                }
                cxjsb_yjbgAdd(formData).then(res=>{
                    let data = res.data;
                    that.yjbg_percent_flag = false;
                    if (data.success) {
                        that.getStatus(that.cxj_cxj_id)
                        document.getElementById('yjbg').value = null;
                        that.$message.success('上传成功');
                        that.get_cxjsb_getSbbyjbg();
                    } else {
                        that.$message.error(data.message);
                    }
                }).catch(err=>{
                    console.log(err)
                    that.yjbg_percent_flag = false;
                })
            }
        },
        downfn(title, res) {
            const data = res.data;
            const url = window.URL.createObjectURL(new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}))
            const link = document.createElement('a')
            link.style.display = 'none'
            link.href = url;
            link.setAttribute('download', title+'.doc')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link)
        }
    },
    mounted() {
        this.cxj_cxj_id = this.$route.query.cxj_cxj_id;
        this.init();
    }
}
</script>
<style lang="less" scoped>
.declareTableInfo {
    margin-top: 24px;
    padding-bottom: 30px;
    border-bottom: 1px solid #EEEEEE;
    input {
        display: none;
    }
    .flex_box {
        display: flex;
    }
    .title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        span {
            font-size: 16px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #3388EE;
            line-height: 22px;
            em {
                color: #CB0C0C;
                font-style: normal;
                font-size:  14px;;
            }
        }
        .btnList {
            button{
                width: 70px;
                height: 32px;
                border: 1px solid #D9D9D9;
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                line-height: 20px;
                margin-left: 10px;
                &.download {
                    color: #fff;
                }
                &.loadboard {
                    width: 100px;
                }
            }
        }
    }
    .tableList {
        margin-top: 21px;
        table {
            margin-top: 20px;
            background: #FFFFFF;
            thead {
                background: #F5F5F5;
                tr {
                    th {
                        height: 54px;
                        font-size: 16px;
                        font-family: PingFangSC-Medium, PingFang SC;
                        font-weight: 500;
                        color: #333333;
                    }
                }
            }
            tbody {
                tr {
                    height: 52px;
                    td {
                        color: #444444;
                        font-size: 14px;
                        font-weight: 400;
                        height: 52px;
                        em {
                            color: #CB0C0C;
                            margin-right: 5px;
                        }
                    }
                    &:nth-child(even){
                        background: #F5F5F5;
                    }
                }
            }
        }
    }
}
</style>
